<template>
<div class="lottery views-container">
  <share-link :config="shareLinkConfig" ref="sharelink">
        <template slot="title">-抽奖</template>
        <template slot="el-form-item">
            <el-form-item label="小程序路径" v-if="shareLinkConfig.params.qrUrl">
                <el-input style="width: 270px;" readonly placeholder="请输入内容" v-model="shareLinkConfig.params.qrUrl" class="input-with-select">
                    <el-button slot="append" @click="handleClipboard(shareLinkConfig.params.qrUrl,$event)">复制</el-button>
                </el-input>
            </el-form-item>
            <el-form-item label="公众号链接" v-if="shareLinkConfig.params.linkUrl">
                <el-input style="width: 270px;" readonly placeholder="请输入内容" v-model="shareLinkConfig.params.linkUrl" class="input-with-select">
                    <el-button slot="append" @click="handleClipboard(shareLinkConfig.params.linkUrl,$event)">复制</el-button>
                </el-input>
            </el-form-item>
        </template>
    </share-link>
    <div class="wlm-table">
        <div class="wlm-table-hearder-btn">
            <router-link tag="span" to="/application/lotteryAdd">
                <el-button size="small" type="primary">添加抽奖</el-button>
            </router-link>
            <router-link tag="span" to="/application/lotteryAddList">
                <el-button size="small" type="warning">抽奖订单列表</el-button>
            </router-link>
             <router-link tag="span" to="/application/luckListSet">
                <el-button size="small" type="primary">抽奖列表页设置</el-button>
            </router-link>
        </div>
        <div class="wlm-table-header">
            <el-form :model="tableFormatData.userTable.files" size="small" label-width="85px" class="retail-form" label-position="right">
                <el-form-item label="" class="filter">
                    <el-form-item label="活动名称：">
                        <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.luck_title" placeholder="请输入活动名称" style="width:160px;"></el-input>
                    </el-form-item>
                    <el-form-item label="开奖方式：">
                        <el-select v-model="tableFormatData.userTable.files.luck_mode" placeholder="请选择" style="width:200px;">
                            <el-option label="全部" value="">
                            </el-option>
                            <el-option label="按时间开奖" :value="1">
                            </el-option>
                            <el-option label="按人数开奖" :value="2">
                            </el-option>
                            <el-option label="手动开奖" :value="3">
                            </el-option>
                        </el-select>
                    </el-form-item>
                     <el-form-item label="抽奖模式：">
                        <el-select v-model="tableFormatData.userTable.files.is_pay" placeholder="请选择" style="width:200px;">
                            <el-option label="全部" value="">
                            </el-option>
                            <el-option label="付费抽奖" :value="1">
                            </el-option>
                            <el-option label="非付费抽奖" :value="2">
                            </el-option>

                        </el-select>
                    </el-form-item>
                    <!-- <el-form-item label="活动时间：">
                        <el-date-picker v-model="tableFormatData.userTable.files.time" value-format="timestamp" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
                        </el-date-picker>
                    </el-form-item> -->
                </el-form-item>
                <el-form-item label="" class="filter-btns">
                    <el-button type="primary" @click="filesSerch">筛选</el-button>
                    <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="wlm-table-content">
            <!-- <el-tabs v-model="tableFormatData.userTable.files.luck_state" type="card" @tab-click="filesSerch">
                <el-tab-pane label="全部活动" name="0"></el-tab-pane>
                <el-tab-pane label="未开奖" name="3"></el-tab-pane>
                <el-tab-pane label="抽奖中" name="2"></el-tab-pane>
                <el-tab-pane label="已开奖" name="1"></el-tab-pane>
            </el-tabs> -->

            <el-table :ref="tableFormatData.userTable.key" :data="tableFormatData.userTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                <!-- <el-table-column type="selection" width="55">
                </el-table-column> -->
                <el-table-column prop="date" label="活动名称"  min-width="60">
                    <template slot-scope="scope">
                        <span>{{scope.row.luck_title}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="活动时间"  min-width="80">
                    <template slot-scope="scope">
                        <p style="white-space: nowrap;">开始时间:{{scope.row.luck_time[0]*1000| parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</p>
                        <p style="white-space: nowrap;">结束时间:{{scope.row.luck_time[1]*1000| parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</p>
                    </template>
                </el-table-column>
                <!-- <el-table-column prop="name" label="活动状态"  min-width="45">
                    <template slot-scope="scope">
                        <span v-if="scope.row.luck_state==1">已开奖</span>

                        <span v-if="scope.row.luck_state==2">抽奖中</span>
                        <span v-if="scope.row.luck_state==3">未开奖</span>
                    </template>
                </el-table-column> -->
                <el-table-column label="开奖方式"  min-width="45">
                    <template slot-scope="scope">
                        <span v-if="scope.row.luck_mode==1">按时间开奖</span>

                        <span v-if="scope.row.luck_mode==2">按人数开奖</span>
                        <span v-if="scope.row.luck_mode==3">手动开奖</span>

                        <p v-if="scope.row.is_pay==1">付费抽奖</p>
                        <p v-if="scope.row.is_pay==2">免费抽奖</p>
                    </template>
                </el-table-column>
                <!-- <el-table-column label="中奖数"  min-width="45">
                    <template slot-scope="scope">
                        <span>{{scope.row.is_luck_count}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="抽奖人数"  min-width="45">
                    <template slot-scope="scope">
                        <span>{{scope.row.user_count}}</span>
                    </template>
                </el-table-column> -->
                <!-- <el-table-column label="活动状态"  min-width="45">
                    <template slot-scope="scope">
                        <span>{{scope.row.pay_order}}</span>
                    </template>
                </el-table-column> -->
                 <el-table-column label="抽奖期数"  min-width="45">
                    <template slot-scope="scope" >
                       <div class=""  >
                          <p>{{scope.row.per_start_end}}</p>
                        <p v-if='scope.row.luck_periods!=0'>共{{scope.row.luck_periods}}期</p>
                       </div>
                    </template>
                </el-table-column>
                <el-table-column label="操作" >
                    <template slot-scope="scope">
                        <div class="operation-group">
                            <!-- <router-link class="wlm-text" tag="span" :to="{path:'/application/lotteryInfoList', query :{ luck_id:scope.row.luck_id}}">
                                <el-button type="text">抽奖用户</el-button>
                            </router-link> -->
                            <!-- <div v-if="scope.row.luck_state==2&&scope.row.luck_mode==3" class="btn-line"></div>
                            <el-button v-if="scope.row.luck_state==2&&scope.row.luck_mode==3" class="wlm-text" type="text" @click="luckOpen(scope.row.luck_id)">开奖</el-button> -->
                             <el-button  class="wlm-text" type="text" @click="luckRecord(scope.row.luck_id)">抽奖记录</el-button>
                            <div class="btn-line"></div>
                            <router-link class="wlm-text" tag="span" :to="{path:'/application/lotteryAdd', query :{ luck_id:scope.row.luck_id}}">
                                <el-button type="text">编辑</el-button>
                            </router-link>
                            <div class="btn-line"></div>
                            <el-button class="wlm-text" type="text" @click="delTableItem(scope.row.luck_id)">删除</el-button>
                            <!-- <div class="btn-line"></div> -->
                            <!-- <el-button class="wlm-text" type="text" @click="sharelink(scope.row.luck_id)">推广</el-button> -->
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-content flex-row flex-justify-e flex-align-c">
                <!-- <el-row class="pagination-btns">
                    <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.userTable.files.checkall" @change="toggleSelection">全部</el-checkbox>
                    <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button>
                </el-row> -->
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  luckList,
  luckDestory,
  luck,
  luckExtension
} from '@/api/application'
import mixins from '@/mixins/mixins'
import ShareLink from '@/components/ShareLink/index'
import clipboard from '@/utils/clipboard'
export default {
  mixins: [mixins.getters('Table')],
  name: 'Lottery',
  components: {
    ShareLink
  },
  data() {
    return {
      blogTitle: '',
      shareLinkConfig: {
        current: 'weChatQr',
        params: {
          qrUrl: '',
          linkUrl: ''
        }
      },
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: luckList,
            delList: luckDestory
            //   msgConfig: {
            //     del: {
            //       type: 'warning',
            //       msg: '此操作会删除用户的所有数据，名下所有平台内如有正在交易的订单、金额，删除后所产生的纠纷由服务商自身承担 如要删除请慎重操作！！'
            //     }
            //   }
          },
          tableData: [],
          files: {
            luck_title: '',
            time: '',
            luck_state: '',
            ids: [],
            checkall: '0',
            Recycle: '1',

          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {
    luckRecord(luck_id){
      this.$router.push({
        path:  "/application/lotteryRecord",
        query: { luck_id }
      }
       )

    },
    handleClipboard(text, event) {
      clipboard(text, event)
    },
    sharelink(luckId) {
      luckExtension({ luck_id: luckId }).then((response) => {
        const { data: { data: { sapp_url, h5_url } } } = response
        this.shareLinkConfig.params.qrUrl = sapp_url
        this.shareLinkConfig.params.linkUrl = h5_url
        this.shareLinkConfig.current = 'linkpath'
      })
      this.shareLinkConfig.params.luck_id = luckId
      this.$refs.sharelink.toggle()
    },
    luckOpen(id) {
      this.$confirm('是否确认开奖?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        luck({ luck_id: id }).then(response => {
          const { data: { msg, code } } = response
          if (code === 1) {
            this.$message({
              type: 'success',
              message: '开奖成功!'
            })
            this.$nextTick(() => {
              this.filesSerch()
            })
          } else {
            this.$message.error(msg)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消开奖'
        })
      })
    }
  }
}
</script>
